//
// Author: Vladimir Migashko <migashko@gmail.com>, (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//

#ifndef FASYS_LIBS_CHANNEL_SERVICE_CHANNEL_SERVER_HPP
#define FASYS_LIBS_CHANNEL_SERVICE_CHANNEL_SERVER_HPP

#include <fas/inet/server.hpp>
#include "aspect.hpp"
#include "connection.hpp"
#include "ichannel_server.hpp"
#include <channels/messages_channels.hpp>

namespace fasys{ namespace service{ namespace channel{

namespace ai = ::fas::inet;

struct f_message
{
  const message_notify& m;

  f_message(const message_notify& m): m(m){}

  template<typename T>
  void operator()(T* t)
  {
    t->outgoing(m);
  }
};

class channel_server
  : public ichannel_server
  , public ai::server<
      aspect,
      aa::aspect<>,
      false,
      ai::IPv4,
      ai::TCP,
      ai::mux_connection<aa::aspect<>, connection>
    >
{
  ::fasys::channels::messages_channels _channels;
public:
  channel_server()
  {
    get_prototype().server = this;
    get_prototype().channels = &_channels;
  }

  void process(message_notify& cmd) 
  {
    for_each( f_message(cmd) );
  }
};

}}}

#endif
